import java.util.Arrays;

public class homework20250212 {
    public static void main(String[] args) {
        int[] array = {2,2,1};
        System.out.println(singleNumber(array));
        int[] array2 = {4,1,2,1,2};
        System.out.println(singleNumber(array2));
    }
    public static int singleNumber(int[] array) {;
        int ret = 0;
        for (int x : array) {
            ret ^= x;
        }
        return ret;
    }
    public static void main8(String[] args) {
        int[] arrary = {1,2,3,4,5,6};
        System.out.println(Arrays.toString(sort2(arrary)));
    }
    public static int[] sort2(int[] array) {
        int i = 0, j = array.length - 1;
        while (i < j) {
            if(array[i] % 2 == 0 && array[j] % 2 != 0) {
                int tmp = array[i];
                array[i] = array[j];
                array[j] = tmp;
                i++;
                j--;
            }else if(array[i] % 2 != 0 && array[j] % 2 !=0) {
                i++;
            }else {
                j--;
            }
        }
        return array;
    }
    public static void main7(String[] args) {
        int[] array = {2,6,4,1};
        System.out.println(isJiShu(array));
        int[] array2 = {1,2,34,3,4,5,7,23,12};
        System.out.println(isJiShu(array2));
    }
    public static boolean isJiShu(int[] array) {
        for (int i = 0; i < array.length - 2; i++) {
            if(array[i] % 2 != 0 && array[i + 1] % 2 != 0 && array[i + 2] != 0) {
                return true;
            }
        }
        return false;
    }
    public static void main6(String[] args) {
        int[] array = {3,2,3};
        System.out.println(findMore(array));
        int[] array2 = {2,2,1,1,1,2,2};
        System.out.println(findMore(array2));
    }
    public static int findMore(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int count = 0;
            for (int j = i; j < array.length; j++) {
                if(array[i] == array[j]) {
                    count++;
                }
            }
            if(count > array[i]/2) {
                return array[i];
            }
        }
        return 0;
    }
    public static void main5(String[] args) {
        int[] array = {4,1,2,1,2};
        System.out.println(find(array));
        int[] array2 = {2,2,1};
        System.out.println(find(array2));
    }
    public static int find(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int count = 0;
            for (int j = 0; j < array.length; j++) {
                if(array[i] == array[j]) {
                    count++;
                }
            }
            if(count == 1) {
                return array[i];
            }
        }
        return 0;
    }
    public static void main4(String[] args) {
        int[] array = {2,7,11,15};
        String a = "abcd";
        System.out.println(a);//字符串变量的哈希值直接打印，因为System.out.println(字符串变量的哈希值)
        System.out.println(sum(array, 9));
        //System.out.println(sum(array, 9));
    }
    public static String sum(int[] array, int target) {
        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if(array[i] + array[j] == target) {
                    int[] array2 = {i,j};
                    return Arrays.toString(array2);//Arrays.toString返回String字符串类型
                }
            }
        }
        return null;
    }
    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(Arrays.toString(sort(array)));
    }
    public static int[] sort(int[] array) {
        int[] array2 = new int[array.length];
        int x = 0, y = array.length - 1;
        for (int i = 0; i < array.length; i++) {
            if(array[i] % 2 == 0){
                array2[x] = array[i];
                x++;
            }else {
                array2[y] = array[i];
                y--;
            }
        }
        return array2;
    }
    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(avg(array));
    }
    public static double avg(int[] array) {
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return (double)sum / array.length;
    }
    public static int[] transform(int[] array) {
        int i = array.length - 1;
        while(i >= 0) {
            array[i]*=2;
            i--;
        }
        return array;
    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(Arrays.toString(transform(array)));
    }
}
